<?php

class Core_Frontend_Module_Concessions_Coupon extends Dcmp_Module_Base {

    protected $name = 'concessions_coupon';
    
    public function install() {

    }

    public function uninstall() {

    }

    public function buildConfig($form) {

    }

    public function render() {
        $otherConcessions ='';
        $concessions = $this->getVariables()->getData('concessions_object');
        if(!$concessions){
            $id = $this->getDynamicParameter('id');
            if(!$id){$id = 1;}
            $concessions = App::getModel('promotion/concessions')->load($id);
        }
        $customers = $concessions->getCustomers()->load();
        
        foreach($customers as $customer){
            $ids[] = $customer->getId();
        }
        if(!empty($ids)){
            $otherConcessions = App::getModel('promotion/collection_concessions')
                    ->joinCustomer()
                    ->filterByPoiId($ids)
                    ->filterByStartTime(date('Y-m-d h-m-s'))
                    ->filterByEndTime(date('Y-m-d h-m-s'))
                    ->neq('a.id', $concessions->getId())
                    ->limit(2,0)
                    ->load();
        }
        $tmpl = $this->getTemplate()->assignMulti(array('other_concessions' => $otherConcessions));
        return $tmpl->render($this->getTemplatePath($this->getValueByKey('template_name'),$this->getValueByKey('template_script')));
    }
}

